package com.jushu.storbox.view.viewImpl;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;

public class MyRelativeLayout extends RelativeLayout{
	private Context mContext;

	public MyRelativeLayout(Context context) {
		super(context);
		initData(context);
	}

	private void initData(Context context) {
		mContext = context;
	}

	public MyRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initData(context);
	}

	public MyRelativeLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		initData(context);
	}
	
	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		Log.i("liuxiang", "relativelayout on touch event run");
		if(mContext instanceof Activity){
			Activity activity = (Activity)mContext;
			keyBoardCancle(activity);
		}
		return super.dispatchTouchEvent(ev);
	}
	
	 public void keyBoardCancle(Activity activity) {

		  View view = activity.getWindow().peekDecorView();
		  if (view != null) {
			  InputMethodManager im = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); 
			  im.hideSoftInputFromWindow(view.getWindowToken(), 0);
		  }
	 }

}
